package com.yphone.ui.login.view;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zzkj.yunphone.R;
import com.yphone.ui.dialog.CommSmallLoadingDialog;
import com.yphone.ui.login.activity.RegisterActivity;
import com.yphone.ui.login.bean.request.VerifiCodeRequestInfo;
import com.yphone.ui.login.contract.VerifiViewContract;
import com.yphone.ui.login.presenter.VerifiViewPresenter;
import com.yphone.utils.NetworkUtils;
import com.yphone.utils.ToastUtils;


public class VerifiView extends LinearLayout implements VerifiViewContract.IView {
    public static final int DELAYED_TIME = 1000;
    public static final int HANDLER_ID = 1;
    public static final int MAX_TIME = 60;
    public static final int VERIFI_LENGTH = 4;
    private OnClickListener mClickListener = new OnClickListener() {
        public void onClick(View v) {
            if (v.getId() == VerifiView.this.mTxtSendVerificatioCode.getId()) {
                if (VerifiView.this.mGetVerifiCodeType == 1) {
                    VerifiView.this.mVerifiCodeRequestInfo.phone = VerifiView.this.mRegisterActivity.getPhoneNumber();
                }
                if (TextUtils.isEmpty(VerifiView.this.mVerifiCodeRequestInfo.phone)) {
                    ToastUtils.showLong((CharSequence) VerifiView.this.getResources().getString(R.string.login_phone_empty));
                } else if (VerifiView.this.mVerifiCodeRequestInfo.phone.length() != 11) {
                    ToastUtils.showLong((CharSequence) v.getContext().getString(R.string.phone_format));
                } else if (!NetworkUtils.isConnected()) {
                    ToastUtils.showLong((CharSequence) VerifiView.this.getContext().getString(R.string.no_wifi_notice));
                } else {
                    CommSmallLoadingDialog.showDialog(VerifiView.this.getContext(), VerifiView.this.getContext().getString(R.string.request_ing));
                    VerifiView.this.mIPresenter.getVerifiCationCode(VerifiView.this.mVerifiCodeRequestInfo, VerifiView.this.mGetVerifiCodeType);
                    VerifiView.this.startCountDownTime();
                }
            }
        }
    };
    /* access modifiers changed from: private */
    public int mGetVerifiCodeType;
    /* access modifiers changed from: private */
    public VerifiViewContract.IPresenter mIPresenter;
    /* access modifiers changed from: private */
    public RegisterActivity mRegisterActivity;
    /* access modifiers changed from: private */
    public int mTime;
    /* access modifiers changed from: private */
    public Handler mTimeHandler = new Handler() {
        public void handleMessage(Message msg) {
            VerifiView.this.mTime = VerifiView.this.mTime - 1;
            if (VerifiView.this.mTime != 0) {
                VerifiView.this.mTxtCountDownTime60.setText(VerifiView.this.getResources().getString(R.string.login_verifi_time, new Object[]{Integer.valueOf(VerifiView.this.mTime)}));
                VerifiView.this.mTimeHandler.sendEmptyMessageDelayed(1, 1000);
            } else {
                VerifiView.this.mTxtCountDownTime60.setVisibility(GONE);
                VerifiView.this.mTxtSendVerificatioCode.setVisibility(VISIBLE);
            }
            super.handleMessage(msg);
        }
    };
    /* access modifiers changed from: private */
    public TextView mTxtCountDownTime60;
    /* access modifiers changed from: private */
    public TextView mTxtSendVerificatioCode;
    private EditText mEdtVerificatioCode;

    /* access modifiers changed from: private */
    public VerifiCodeRequestInfo mVerifiCodeRequestInfo;

    public VerifiView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    public VerifiView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public VerifiView(Context context) {
        super(context);
        init();
    }

    private void init() {
        initView();
        initData();
        initListener();
    }

    private void initData() {
        this.mIPresenter = new VerifiViewPresenter(this);
    }

    public void initListener() {
        this.mTxtSendVerificatioCode.setOnClickListener(this.mClickListener);
    }

    public void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.login_verifi_view, this);
        this.mEdtVerificatioCode = (EditText) findViewById(R.id.login_verifi_view_edt_verificatio_code);
        this.mTxtSendVerificatioCode = (TextView) findViewById(R.id.login_verifi_view_txt_send_verificatio_code);
        this.mTxtCountDownTime60 = (TextView) findViewById(R.id.login_verifi_view_txt_count_down_time_60);
    }

    public void setInfo(Activity activity, int type) {
        this.mGetVerifiCodeType = type;
        if (type == 1) {
            this.mRegisterActivity = (RegisterActivity) activity;
        }
        this.mVerifiCodeRequestInfo = new VerifiCodeRequestInfo();
    }

    /* access modifiers changed from: private */
    public void startCountDownTime() {
        this.mTimeHandler.removeMessages(1);
        this.mTime = 60;
        this.mTxtCountDownTime60.setText(getResources().getString(R.string.login_verifi_time, new Object[]{Integer.valueOf(this.mTime)}));
        if (this.mTxtCountDownTime60.getVisibility() == GONE) {
            this.mTxtCountDownTime60.setVisibility(VISIBLE);
            this.mTxtSendVerificatioCode.setVisibility(GONE);
        }
        this.mTimeHandler.sendEmptyMessageDelayed(1, 1000);
    }

    public String getVerifiNum() {
        String checkCode = this.mEdtVerificatioCode.getText().toString().trim();
        if (TextUtils.isEmpty(checkCode)) {
            ToastUtils.showLong((CharSequence) getResources().getString(R.string.login_verifi_code_empty));
        } else if (checkCode.length() < 4) {
            ToastUtils.showLong((CharSequence) getResources().getString(R.string.login_verifi_code_four));
        }
        return checkCode;
    }

    public String getVerifiCode() {
        return this.mEdtVerificatioCode.getText().toString().trim();
    }

    /* access modifiers changed from: protected */
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
    }

    /* access modifiers changed from: protected */
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.mIPresenter.destory();
    }
}